<template>
  <div class="approval-list">
    <h3>待我审批</h3>
    <el-table :data="approvalList" style="width: 100%" v-loading="loading">
      <el-table-column prop="type" label="流程类型"></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="applicant" label="申请人"></el-table-column>
      <el-table-column prop="createTime" label="申请时间"></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="handleApprove(scope.row)">审批</el-button>
          <el-button size="mini" @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 审批对话框 -->
    <el-dialog title="审批" :visible.sync="approvalDialogVisible" width="500px">
      <el-form :model="approvalForm" label-width="80px">
        <el-form-item label="审批结果">
          <el-radio-group v-model="approvalForm.result">
            <el-radio label="approve">同意</el-radio>
            <el-radio label="reject">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审批意见">
          <el-input type="textarea" v-model="approvalForm.comment" rows="4"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="approvalDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitApproval">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      approvalList: [
        {
          id: 1,
          type: '请假申请',
          title: '事假申请-张三',
          applicant: '张三',
          createTime: '2025-03-11 10:00:00'
        },
        {
          id: 2,
          type: '请假申请',
          title: '年假申请-李四',
          applicant: '李四',
          createTime: '2025-03-11 11:00:00'
        }
      ],
      approvalDialogVisible: false,
      approvalForm: {
        result: 'approve',
        comment: ''
      },
      currentItem: null
    }
  },
  methods: {
    handleApprove(row) {
      this.currentItem = row
      this.approvalDialogVisible = true
      this.approvalForm = {
        result: 'approve',
        comment: ''
      }
    },
    handleDetail(row) {
      // 根据流程类型跳转到对应的详情页
      if (row.type === '请假申请') {
        this.$router.push({
          path: '/main/renshi/kaoqing/qingjia',
          query: { id: row.id, type: 'view' }
        })
      }
    },
    submitApproval() {
      if (!this.approvalForm.comment) {
        this.$message.error('请填写审批意见')
        return
      }
      // TODO: 调用审批接口
      this.$message.success('审批提交成功')
      this.approvalDialogVisible = false
      // 刷新列表
      this.approvalList = this.approvalList.filter(item => item.id !== this.currentItem.id)
    }
  }
}
</script>

<style lang="scss" scoped>
.approval-list {
  h3 {
    margin-bottom: 20px;
  }
}
</style> 